import request from "@/utils/request";
import {DictFormType, DictTableType} from "@/api/sys/admin/dict/types";
import {DictOptions} from "@/utils/common-types";
import {PATH_SYS_ADMIN} from "@/utils/constant";

const baseUrl = PATH_SYS_ADMIN + '/dict/'

/**
 * 查询字典列表 - 带分页
 * @param data
 */
export function getDictListApi(data: PageQuery<DictTableType>): PromisePageListType<DictTableType> {
    return request.post(baseUrl + 'list', data)
}

/**
 * 通过字典id获取字典信息
 * @param id
 */
export function getDictByIdApi(id: number): Promise<DictFormType> {
    return request.get(baseUrl + id)
}

/**
 * 修改字典
 * @param id
 * @param data
 */
export function editDictApi(id: number, data: DictFormType): Promise<any> {
    return request.patch(baseUrl + id, data)

}

/**
 * 添加字典
 * @param data
 */
export function addDictApi(data: DictFormType): Promise<any> {
    return request.post(baseUrl, data)

}

/**
 * 删除字典
 * @param id
 */
export function deleteDictApi(id: number): Promise<any> {
    return request.delete(baseUrl + id)
}

/**
 * 获取所有的字典的code
 */
export function getCodeListApi(): Promise<string []> {
    return request.get(baseUrl + 'code-list')
}

/**
 * 通过parentCode获取列表
 * @param parentCode
 */
export function getDictOptions(parentCode: string): Promise<DictOptions[]> {
    return request.get(baseUrl + 'code/' + parentCode)
}